﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UCOLOR.Extend;
using UCOLOR.DAL.Helper;
namespace UCOLOR.Model
{
    public class DataHelper
    {
        #region 新数据
        /// <summary>
        /// 一级产品目录
        /// </summary>
        /// <returns></returns>
        public static IList<UCOLOR.Model.PartProductCode> GetPartProductCode(string product_code="")
        {
            DataToObjet<PartProductCode> dto = new DataToObjet<PartProductCode>();
            var dt = SqliteDataHelper.GetPartProductCodeTab(product_code);
            return dto.DatatableToObject(dt);
        }

        /// <summary>
         /// 获取参数值
         /// </summary>
         /// <param name="param"></param>
         /// <returns></returns>
        public static String GetParameterInfo(string param)
        {
            return SqliteDataHelper.GetParameterInfo(param);
        }
        public static IList<UCOLOR.Model.ClientMessage> GetClientMessage()
        {
            DataToObjet<ClientMessage> dto = new DataToObjet<ClientMessage>();
            var dt = SqliteDataHelper.GetClientMessageTab();
            return dto.DatatableToObject(dt);
        }


        public static IList<UCOLOR.Model.ExhibitionGroup> GetExhibitionGroup()
        {
            DataToObjet<ExhibitionGroup> dto = new DataToObjet<ExhibitionGroup>();
            var dt = SqliteDataHelper.GetExhibitionGroupTab();
            return dto.DatatableToObject(dt);
        }

        //public static PartProductCode GetPartProductCode(string product_code)
        //{
        //    DataToObjet<PartProductCode> dto = new DataToObjet<PartProductCode>();
        //    var dt = SqliteDataHelper.GetPartProductCodeTab();
        //    return dto.DatatableToObject(dt).Where(p=>p.product_code==product_code).First();
        //}

        public static UCOLOR.Model.SalesPart GetSalesPart(string catalog_no)
        {
            DataToObjet<SalesPart> dto = new DataToObjet<SalesPart>();
            var dt = SqliteDataHelper.GetSalesPartTab(catalog_no);
            return dto.DatatableToObject(dt)[0];
        }
        

        /// <summary>
        /// 
        /// </summary>
        /// <param name="groupid"></param>
        /// <returns></returns>
        public static IList<UCOLOR.Model.ExhibitionGroupItem> GetExhibitionGroupItem(string groupid)
        {
            DataToObjet<ExhibitionGroupItem> dto = new DataToObjet<ExhibitionGroupItem>();
            var dt = SqliteDataHelper.GetExhibitionGroupItemTab(groupid);
            return dto.DatatableToObject(dt);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="groupid"></param>
        /// <returns></returns>
        public static IList<UCOLOR.Model.ExhibitionGroupItem> GetExhibitionGroupItemByCatalog(string catalog_no)
        {
            DataToObjet<ExhibitionGroupItem> dto = new DataToObjet<ExhibitionGroupItem>();
            var dt = SqliteDataHelper.GetExhibitionGroupItemTabByCatalog(catalog_no);
            return dto.DatatableToObject(dt);
        }


        /// <summary>
        /// 获取二级分类
        /// </summary>
        /// <param name="product_code">一级分类UI</param>
        /// <returns></returns>
        public static IList<PartProductFamily> GetPartProductFamily(string product_code = "")
        {
            DataToObjet<PartProductFamily> dto = new DataToObjet<PartProductFamily>();
            var dt = SqliteDataHelper.GetPartProductFamilyTab(product_code);
            return dto.DatatableToObject(dt);
        }



        private static string Image_root = "";
        public static String GetIMAGE_ROOT()
        {
            //DataToObjet<SystemParameter> dto =  new DataToObjet<SystemParameter>();
            if(string.IsNullOrEmpty(Image_root))
                Image_root = SqliteDataHelper.GetIMAGE_ROOT();
            return Image_root;
            //return dto.DatatableToObject(dt);
        }


        /// <summary>
        /// 获取模版类型
        /// </summary>
        /// <returns></returns>
        public static IList<SalesTemplateType> GetSalesTemplateType()
        {
            DataToObjet<SalesTemplateType> dto = new DataToObjet<SalesTemplateType>();
            var dt = SqliteDataHelper.GetSalesTemplateTypeTab();
            return dto.DatatableToObject(dt);
        }

        /// <summary>
        /// 根据产品获取模版类型
        /// </summary>
        /// <returns></returns>
        public static IList<SalesTemplateType> GetSalesTemplateType(string catalog_no)
        {
            DataToObjet<SalesTemplateType> dto = new DataToObjet<SalesTemplateType>();
            var dt = SqliteDataHelper.GetSalesTemplateTypeTab(catalog_no);
            return dto.DatatableToObject(dt);
        }
        /// <summary>
        /// 取得产品关联的模板
        /// </summary>
        /// <returns></returns>
        public static IList<SalesCatalogTemplate> GetSalesCatalogTemplate(string catalog_no)
        {
            DataToObjet<SalesCatalogTemplate> dto = new DataToObjet<SalesCatalogTemplate>();
            var dt = SqliteDataHelper.GetSalesCatalogTemplateTab(catalog_no);
            return dto.DatatableToObject(dt);
        }
        /// <summary>
        /// 获取模版数据
        /// </summary>
        /// <param name="template_type"></param>
        /// <returns></returns>
        public static IList<SalesTemplate> GetSalesTemplate(string template_type,bool UseWhere = false)
        {
            DataToObjet<SalesTemplate> dto = new DataToObjet<SalesTemplate>();
            var dt = SqliteDataHelper.GetSalesTemplateTab(template_type,UseWhere);
            return dto.DatatableToObject(dt);
        }

        /// <summary>
        /// 获取模版页数据
        /// </summary>
        /// <param name="template_type"></param>
        /// <returns></returns>
        public static IList<SalesTemplatePage> GetSalesTemplatePage(string template_id)
        {
            DataToObjet<SalesTemplatePage> dto = new DataToObjet<SalesTemplatePage>();
            var dt = SqliteDataHelper.GetSalesTemplatePageTab(template_id);
            return dto.DatatableToObject(dt);
        }
        #endregion


        //public static IList<ProductCategory> getCategorys()
        //{
        //    //var cg = new ProductCategory();
        //    DataToObjet<ProductCategory> dto = new DataToObjet<ProductCategory>();
        //    System.Data.DataTable dt = SqliteDataHelper.GetCategory();
        //    return  dto.DatatableToObject(dt);
        //}

        //public static IList<ProductCategory> getCategorys(string parameter)
        //{
        //   // var cg = new ProductCategory();
        //    DataToObjet<ProductCategory> dto = new DataToObjet<ProductCategory>();
        //    System.Data.DataTable dt = SqliteDataHelper.GetCategory(parameter);
        //    return dto.DatatableToObject(dt);
        //}

        //public static IList<ProductPicture> getProductPictures(int productID)
        //{
        //    DataToObjet<ProductPicture> dto = new DataToObjet<ProductPicture>();
        //    System.Data.DataTable dt = SqliteDataHelper.GetProductPictureByID(productID);
        //    return dto.DatatableToObject(dt);
        //}
        /// <summary>
        /// 取得图片信息
        /// </summary>
        /// <param name="product_code">当不为空时，按这个条件查询</param>
        /// <param name="product_family">当不为空时，按这个条件查询</param>
        /// <returns></returns>
        public static IList<SalesPart> getSalesPart(string product_code, string product_family)
        {
            DataToObjet<SalesPart> dto = new DataToObjet<SalesPart>();
            System.Data.DataTable dt = SqliteDataHelper.GetSalesPartTab(product_code,product_family);
            return dto.DatatableToObject(dt);
        }
        public static IList<SalesPart> getSalesPartWhere(string where)
        {
            DataToObjet<SalesPart> dto = new DataToObjet<SalesPart>();
            System.Data.DataTable dt = SqliteDataHelper.GetSalesPartTabWhere(where);
            return dto.DatatableToObject(dt);
        }
        public static IList<SalesPartAssist> getSalesPartAssist(string catalog_no)
        {
            DataToObjet<SalesPartAssist> dto = new DataToObjet<SalesPartAssist>();
            System.Data.DataTable dt = SqliteDataHelper.GetSalesPartAssist(catalog_no);
            return dto.DatatableToObject(dt);
        }
        //public static IList<Product> getProducts(string parameter)
        //{
        //    //            var cg = new ProductCategory();
        //    DataToObjet<Product> dto = new DataToObjet<Product>();
        //    System.Data.DataTable dt = SqliteDataHelper.GetProducts(parameter);
        //    return dto.DatatableToObject(dt);
        //}


        //public static IList<UserCart> getUserCarts(string parameter)
        //{
        //    //            var cg = new ProductCategory();
        //    DataToObjet<UserCart> dto = new DataToObjet<UserCart>();
        //    System.Data.DataTable dt = SqliteDataHelper.GetUserCarts(parameter);
        //    return dto.DatatableToObject(dt);
        //}


        //public static Product getProduct(int productID)
        //{
        //    DataToObjet<Product> dto = new DataToObjet<Product>();
        //    System.Data.DataTable dt = SqliteDataHelper.GetProductByID(productID);
        //    IList<Product> list =  dto.DatatableToObject(dt);
        //    if (list != null || list.Count > 0)
        //    {
        //        return list[0];
        //    }
        //    return null;
        //}


    }
}
